package cn.com.callback

import cn.com.kh.KHUtil
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.com.callback.ServiceBackInvoke
import cn.com.elite.EliteBean;
import cn.com.elite.Util;
import java.text.SimpleDateFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.kh.getProperty;
/**
 *
 * @Title: aipHSTcust* @Description:华盛证券 将开户客户数据信息实时推送至CRM系统 --外部接口
 * @author: TH
 * @date 2021-07-05 10:28:00
 *
 */

public class aipHSTcust implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(aipHSTcust.class);
    String custapiid = getProperty.get("custapiid");
    String custapikey = getProperty.get("custapikey");
    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {
        response.setCharacterEncoding("UTF-8");

        String getMethod = request.getMethod();

        log.debug("getMethod:" + getMethod);
        long endTime ;
        String inData = "";
        String outData = "";
        String dataSourceID = "dataSource";

        BufferedReader iny = null;
        if (getMethod.equals("GET")) {
            inData = request.getParameter("data");
            log.debug("原始Get请求参数:" + inData);
        } else {
            InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
            iny = new BufferedReader(reader);
            String line;
            while ((line = iny.readLine()) != null) {
                inData += line;
            }
            log.debug("原始Post请求参数:" + inData);
        }

        try {
            long startTime = System.currentTimeMillis();

            // 调用处理信息
            JSONObject inObject = JSONObject.parseObject(inData);
            log.debug("处理前的Json：" + inObject.toString());
            def apiid = inObject.getString("apiid");
            if(custapiid!=apiid){

                return "{\"resultcode\":\"0\",\"resultmessage\":\"处理失败(apiid不匹配),调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":[]}";
            }
            def timestamp = inObject.getString("timestamp");
            def sign = inObject.getString("sign");
            def apitype = inObject.getString("apitype");
            log.debug("解析信息-" + "apiid: " + apiid + "timestamp: " + timestamp + "	sign: " + sign + "	apitype: " + apitype);

            //  String apikey = "c5e5e59567162a6be0533228d50a17e9";
            String signfront = "apiid" + "=" + apiid + "&" + "apikey" + "=" + custapikey + "&" + "timestamp" + "=" + timestamp;
            log.debug("sign加密MD5前：" + signfront);

            String signafter = Util.getMD5Str(signfront);
            log.debug("sign加密MD5后：" + signafter);

            if (!signafter.equals(sign)) {
                log.error("处理失败(sign签名错误)!");
                endTime = System.currentTimeMillis();
                return "{\"resultcode\":\"0\",\"resultmessage\":\"处理失败(sign签名错误),调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":[]}";
            }
            //传 deposit 属入金状态同步
            if(apitype=="deposit"){
                outData = depositCustData(eliteBean, inObject, dataSourceID);
            }else if(apitype=="details"){//传 details 属入金详情同步
                outData = detailsCustData(eliteBean, inObject, dataSourceID);
            }else if(apitype=="remind"){//传 remind 属入金状态提醒
                outData = remindCustData(eliteBean, inObject, dataSourceID);
            }else{//否则按名单下发同步 account
                outData = dealCustData(eliteBean, inObject, dataSourceID);
            }

        } catch (Exception e) {
            log.error("接口处理异常" + e.getMessage());
            outData = "{\"resultcode\":\"0\",\"resultmessage\":\"处理失败(" + e.getMessage() + ")\",\"data\":[]}";
        }

        log.debug("开户(入金)客户信息完成返回结果:" + outData);

        return outData;
    }

    // 处理开户名单任务
    public static String dealCustData(EliteBean eliteBean, JSONObject inObject, String dataSourceID) {

        long startTime = System.currentTimeMillis();
        long endTime = System.currentTimeMillis();

        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createdate = dateformat.format(System.currentTimeMillis());

        // 生成批次号
        String batch_guid = KHUtil.getRandomString(36).toUpperCase();

        // 定义返回对象
        JSONObject resultJson = new JSONObject();

        try {

            JSONArray arrJsonArray = inObject.getJSONArray("data");
            int arrInt = arrJsonArray.size();
            log.debug("接入List数量:" + arrInt);

            String[] insertSQL = new String[arrInt + 2];

            for (int i = 0; i < arrInt; i++) {

                JSONObject arrSmsJson = arrJsonArray.getJSONObject(i);

                String customerid = KHUtil.FastJsonNull(arrSmsJson.getString("customerid"));//华盛号
                String customername = KHUtil.FastJsonNull(arrSmsJson.getString("customername"));//客户姓名
                String gender = KHUtil.FastJsonNull(arrSmsJson.getString("gender"));//客户性别
                String phone = KHUtil.FastJsonNull(arrSmsJson.getString("phone"));//手机号码
                String accounttype = KHUtil.FastJsonNull(arrSmsJson.getString("accounttype"));//账户类型
                String tradepermission = KHUtil.FastJsonNull(arrSmsJson.getString("tradepermission"));//已开通账户
                String register = KHUtil.FastJsonNull(arrSmsJson.getString("register"));//注册渠道
                String registertime = KHUtil.FastJsonNull(arrSmsJson.getString("registertime"));//注册时间
                String opentime = KHUtil.FastJsonNull(arrSmsJson.getString("opentime"));//开户时间
                String inviterhstno = KHUtil.FastJsonNull(arrSmsJson.getString("inviterhstno"));//邀请人华盛号
                String invitername = KHUtil.FastJsonNull(arrSmsJson.getString("invitername"));//邀请人姓名
                String invitertype = KHUtil.FastJsonNull(arrSmsJson.getString("invitertype"));//邀请人类型
                String register_id=KHUtil.FastJsonNull(arrSmsJson.getString("register_id"));//注册渠道id
                String registerstatus=KHUtil.FastJsonNull(arrSmsJson.getString("registerstatus"));//开户状态
                String stashtime=KHUtil.FastJsonNull(arrSmsJson.getString("stashtime"));//暂存时间
                String audittime=KHUtil.FastJsonNull(arrSmsJson.getString("audittime"));//审核时间

                String deal_result = KHUtil.isNullMSG("customerid", customerid)  + KHUtil.isNullMSG("phone", phone) + KHUtil.isNullMSG("registertime",registertime) + KHUtil.isNullMSG("register", register)+ KHUtil.isNullMSG("register_id", register_id);
                int deal_flag = KHUtil.isNull(deal_result) ? 0 : -1;

                //非空校验
                if(stashtime==""){
                    stashtime=null;
                }else{
                    stashtime="'"+stashtime+"'";
                }
                if(audittime==""){
                    audittime=null;
                }else{
                    audittime="'"+audittime+"'";
                }
				//处理异常客户名称
                customername=customername.replaceAll("'","\'");
                customername=customername.replaceAll("'","\"");
                //处理注销的手机号码
                phone = phone.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'");
				
                insertSQL[i] = "Insert Into Account_Information (Customerid, Customername, Gender, Phone, Accounttype,tradepermission, Register, Registertime, Opentime, Batch_Guid, Inviter_Hstno, Inviter_Name, Inviter_Type, Createtime, Deal_Flag,register_id,Deal_Result,registerstatus,stashtime,audittime) Values ('" + customerid + "', '" + customername + "', '" + gender + "', '" + phone + "', '" + accounttype + "', '" + tradepermission + "', '" + register + "', '" + registertime + "', '" + opentime + "', '" + batch_guid + "', '" + inviterhstno + "', '" + invitername + "', " +"'" + invitertype + "', Now(), '" + deal_flag + "','"+ register_id+"', '" + deal_result + "', '" + registerstatus + "', " + stashtime + ", " + audittime + ")";

            }

            // 处理批次信息
            String enddate = dateformat.format(System.currentTimeMillis());
            insertSQL[arrInt] = "INSERT INTO account_information_batch (batch_guid , type , createdate , enddate , batch_num ) VALUES ('" + batch_guid + "', 'aipHSTcust', '" + createdate + "', '" + enddate + "', " + arrInt + ")";
            insertSQL[arrInt + 1] = "Insert Into Elitethread (Thread_Guid, Createdate, Status, Content, Type) Values (uuid(), now(), '0', '" + batch_guid + "', 'aipHSTcust')";
            log.debug("提交数据库操作SQL集:" + insertSQL.toString());

            // 将数据插入数据库
            int[] sqlResult = eliteBean.updateBatch(insertSQL, dataSourceID);
            log.debug("提交数据库操作SQL结果:" + sqlResult.toString());

            // 生成处理完成时间
            endTime = System.currentTimeMillis();

            // 包装拼接返回JSONObject
            resultJson.put("resultcode", 1);
            resultJson.put("resultmessage", "处理完成,调用问题处理时长(毫秒):" + (endTime - startTime));
        } catch (Exception e) {
            endTime = System.currentTimeMillis();
            resultJson.put("resultcode", 4);
            resultJson.put("resultmessage", "处理失败:(" + e.getMessage() + ")" + "处理完成,调用问题处理时长(毫秒):" +(endTime -startTime));

        }

        return resultJson.toString();
    }

    // 处理入金状态任务
    public static String depositCustData(EliteBean eliteBean, JSONObject inObject, String dataSourceID) {

        long startTime = System.currentTimeMillis();
        long endTime = System.currentTimeMillis();

        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createdate = dateformat.format(System.currentTimeMillis());

        // 生成批次号
        String batch_guid = KHUtil.getRandomString(36).toUpperCase();

        // 定义返回对象
        JSONObject resultJson = new JSONObject();

        try {

            JSONArray arrJsonArray = inObject.getJSONArray("data");
            int arrInt = arrJsonArray.size();
            log.debug("接入List数量:" + arrInt);

            String[] insertSQL = new String[arrInt*3];

            for (int i = 0; i < arrInt; i++) {

                JSONObject arrSmsJson = arrJsonArray.getJSONObject(i);

                String customerId = KHUtil.FastJsonNull(arrSmsJson.getString("customerId"));//华盛号
                String taskId = KHUtil.FastJsonNull(arrSmsJson.getString("taskId"));//任务id
                String customerEnName = KHUtil.FastJsonNull(arrSmsJson.getString("customerEnName"));//客户英文姓名
                String remittanceBankName = KHUtil.FastJsonNull(arrSmsJson.getString("remittanceBankName"));//汇款银行
                String remittanceCardNo = KHUtil.FastJsonNull(arrSmsJson.getString("remittanceCardNo"));//汇款银行卡号
                String receiveBankName = KHUtil.FastJsonNull(arrSmsJson.getString("receiveBankName"));//收款银行
                String receiveCardNo = KHUtil.FastJsonNull(arrSmsJson.getString("receiveCardNo"));//收款银行卡号
                String chargeType = KHUtil.FastJsonNull(arrSmsJson.getString("chargeType"));//入金方式(枚举值id，取华盛系统内部统一)
                String chargeTypeDesc = KHUtil.FastJsonNull(arrSmsJson.getString("chargeTypeDesc"));//入金方式(名称)
                String subBankCardNo = KHUtil.FastJsonNull(arrSmsJson.getString("subBankCardNo"));//子账户号码(若为子账户入金需要传子账户号码)
                String depositStatus = KHUtil.FastJsonNull(arrSmsJson.getString("depositStatus"));//入金状态 1待处理 2处理中 3已完成 4已驳回 5 撤销申请
                String rejectMsg = KHUtil.FastJsonNull(arrSmsJson.getString("rejectMsg"));//驳回原因（名称，若入金状态为驳回需传详细原因）
                String depositAmount = KHUtil.FastJsonNull(arrSmsJson.getString("depositAmount"));//入金金额
                String currencyCode=KHUtil.FastJsonNull(arrSmsJson.getString("currencyCode"));//金币种
                String depositApplyTime=KHUtil.FastJsonNull(arrSmsJson.getString("depositApplyTime"));//入金申请时间
                String depositUpdateTime=KHUtil.FastJsonNull(arrSmsJson.getString("depositUpdateTime"));//各状态更新时间
                String arrivalRecordId=KHUtil.FastJsonNull(arrSmsJson.getString("arrivalRecordId"));//到账ID


                String deal_result = KHUtil.isNullMSG("customerId", customerId)  +KHUtil.isNullMSG("taskId", taskId)  + KHUtil.isNullMSG("chargeType", chargeType) + KHUtil.isNullMSG("chargeTypeDesc",chargeTypeDesc) + KHUtil.isNullMSG("depositStatus", depositStatus)+ KHUtil.isNullMSG("depositAmount", depositAmount)+ KHUtil.isNullMSG("currencyCode", currencyCode)+ KHUtil.isNullMSG("depositApplyTime", depositApplyTime)+ KHUtil.isNullMSG("depositUpdateTime", depositUpdateTime);
                int deal_flag = KHUtil.isNull(deal_result) ? 0 : -1;

                //非空校验
                if(depositApplyTime==""){
                    depositApplyTime=null;
                }else{
                    depositApplyTime="'"+depositApplyTime+"'";
                }
                if(depositUpdateTime==""){
                    depositUpdateTime=null;
                }else{
                    depositUpdateTime="'"+depositUpdateTime+"'";
                }
				
				//处理异常客户名称
                customerEnName=customerEnName.replaceAll("'","\'");
                customerEnName=customerEnName.replaceAll("'","\"");

                insertSQL[i*3] = "Insert Into Account_Information_Deposit (customerId,taskId,customerEnName,remittanceBankName,remittanceCardNo,receiveBankName,receiveCardNo,chargeType,chargeTypeDesc,subBankCardNo,depositStatus,rejectMsg,depositAmount,currencyCode,depositApplyTime,depositUpdateTime,Batch_Guid,Createtime,arrivalRecordId,deal_flag,deal_result) Values ('" + customerId+ "','" + taskId+ "', '" + customerEnName+ "', '" + remittanceBankName+ "', '" + remittanceCardNo+ "', '" + receiveBankName+ "', '" + receiveCardNo+ "', '" + chargeType+ "', '" + chargeTypeDesc+ "', '" + subBankCardNo+ "', '" + depositStatus+ "', '" + rejectMsg+ "', '" + depositAmount+ "', '" + currencyCode+ "', " + depositApplyTime + ", " + depositUpdateTime + ", '" + batch_guid+ "', Now(), '" + arrivalRecordId+ "','"+deal_flag+"','"+deal_result+"')";
                //落库更新customer 入金状态 与 客户英文名称
                //insertSQL[i*3+1] = "update  Customer c  set c.depositstatus=case when  c.depositstatus='3' then c.depositstatus else '" + depositStatus+ "' end ,c.customernamebb=case when c.customernamebb is null or c.customernamebb='' then '" + customerEnName+ "' else c.customernamebb end   where c.CUSTOMER_ID='"+customerId+"'";
				insertSQL[i*3+1] = "update  Customer c  set c.depositstatus=case when  c.depositstatus='3' then c.depositstatus else '" + depositStatus+ "' end ,c.customernamebb=case when c.customernamebb is null or c.customernamebb='' then '" + customerEnName+ "' else c.customernamebb end,c.depositUpdateTime=case when c.depositUpdateTime is null then " + depositUpdateTime+ " else c.depositUpdateTime end  where c.CUSTOMER_ID='"+customerId+"'";
                insertSQL[i*3+2] = "update  hst_deposit_status_remind h  set h.DepositStatus='2' where 1=1 and h.customerid='"+customerId+"' and h.arrivalRecordId='"+arrivalRecordId+"' and h.DepositStatus='1'";

            }

            // 处理批次信息
            String enddate = dateformat.format(System.currentTimeMillis());
            //insertSQL[arrInt] = "INSERT INTO account_information_batch (batch_guid , type , createdate , enddate , batch_num ) VALUES ('" + batch_guid + "', 'aipHSTdepositcust', '" + createdate + "', '" + enddate + "', " + arrInt + ")";
            //insertSQL[arrInt + 1] = "Insert Into Elitethread (Thread_Guid, Createdate, Status, Content, Type) Values (uuid(), now(), '0', '" + batch_guid + "', 'aipHSTdepositcust')";
            log.debug("提交数据库操作SQL集:" + insertSQL.toString());

            // 将数据插入数据库
            int[] sqlResult = eliteBean.updateBatch(insertSQL, dataSourceID);
            log.debug("提交数据库操作SQL结果:" + sqlResult.toString());

            //落库更新customer 入金状态 与 客户英文名称
            //String updateCustSQL = "update  Customer c LEFT JOIN Account_Information_Deposit a ON c.CUSTOMER_ID=a.customerId set c.depositstatus=a.depositStatus,c.customernamebb=case when c.customernamebb is null or c.customernamebb='' then a.customerEnName else c.customernamebb end   where a.Batch_Guid='"+batch_guid+"'";
            //eliteBean.update(updateCustSQL, "dataSource");

            // 生成处理完成时间
            endTime = System.currentTimeMillis();

            // 包装拼接返回JSONObject
            resultJson.put("resultcode", 1);
            resultJson.put("resultmessage", "处理完成,调用问题处理时长(毫秒):" + (endTime - startTime));
        } catch (Exception e) {
            endTime = System.currentTimeMillis();
            resultJson.put("resultcode", 4);
            resultJson.put("resultmessage", "处理失败:(" + e.getMessage() + ")" + "处理完成,调用问题处理时长(毫秒):" +(endTime -startTime));

        }

        return resultJson.toString();
    }

    // 处理入金 归因渠道详情任务
    public static String detailsCustData(EliteBean eliteBean, JSONObject inObject, String dataSourceID) {

        long startTime = System.currentTimeMillis();
        long endTime = System.currentTimeMillis();

        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createdate = dateformat.format(System.currentTimeMillis());

        // 生成批次号
        String batch_guid = KHUtil.getRandomString(36).toUpperCase();

        // 定义返回对象
        JSONObject resultJson = new JSONObject();

        try {

            JSONArray arrJsonArray = inObject.getJSONArray("data");
            int arrInt = arrJsonArray.size();
            log.debug("接入List数量:" + arrInt);

            String[] insertSQL = new String[arrInt*2];

            for (int i = 0; i < arrInt; i++) {

                JSONObject arrSmsJson = arrJsonArray.getJSONObject(i);

                String customerId = KHUtil.FastJsonNull(arrSmsJson.getString("customerId"));//华盛号
                String latestLogonTime = KHUtil.FastJsonNull(arrSmsJson.getString("latestLogonTime"));//最新登录时间
                String firstAssetTime = KHUtil.FastJsonNull(arrSmsJson.getString("firstAssetTime"));//首入资产时间
                String firstAssetChannelId = KHUtil.FastJsonNull(arrSmsJson.getString("firstAssetChannelId"));//首入资产渠道id
                String firstAssetChannel = KHUtil.FastJsonNull(arrSmsJson.getString("firstAssetChannel"));//首入资产渠道
                String firstAssetAttribution = KHUtil.FastJsonNull(arrSmsJson.getString("firstAssetAttribution"));//首入资产归因
                String openingChannelId = KHUtil.FastJsonNull(arrSmsJson.getString("openingChannelId"));//开户渠道id
                String openingChannelName = KHUtil.FastJsonNull(arrSmsJson.getString("openingChannelName"));//开户渠道名称
                String openingAttribution = KHUtil.FastJsonNull(arrSmsJson.getString("openingAttribution"));//开户归因
                String openingTime = KHUtil.FastJsonNull(arrSmsJson.getString("openingTime"));//开户时间
                String transferChannelId = KHUtil.FastJsonNull(arrSmsJson.getString("transferChannelId"));//转绑渠道id
                String transferChannelName = KHUtil.FastJsonNull(arrSmsJson.getString("transferChannelName"));//转绑渠道名称
                String transferAttribution=KHUtil.FastJsonNull(arrSmsJson.getString("transferAttribution"));//转绑归因
                String transferTime=KHUtil.FastJsonNull(arrSmsJson.getString("transferTime"));//转绑时间
                String registerAttribution=KHUtil.FastJsonNull(arrSmsJson.getString("registerAttribution"));//注册归因
                String registerTime=KHUtil.FastJsonNull(arrSmsJson.getString("registerTime"));//注册时间

                String registerChannelId=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelId"));//注册渠道id
                String registerChannelName=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelName"));//转绑渠道名称
                String registerChannelId1=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelId1"));//注册渠道一级id
                String registerChannelName1=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelName1"));//注册渠道一级名称
                String registerChannelId2=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelId2"));//注册渠道二级id
                String registerChannelName2=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelName2"));//注册渠道二级名称
                String registerChannelId3=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelId3"));//注册渠道三级id
                String registerChannelName3=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelName3"));//注册渠道三级名称
                String registerChannelId4=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelId4"));//注册渠道四级id
                String registerChannelName4=KHUtil.FastJsonNull(arrSmsJson.getString("registerChannelName4"));//注册渠道四级名称

                //log.debug("customerId" + KHUtil.isNullMSG("customerId", customerId));
                //log.debug("registerChannelId" + KHUtil.isNullMSG("registerChannelId", registerChannelId));
                //log.debug("registerChannelName" + KHUtil.isNullMSG("registerChannelName", registerChannelName));

                String deal_result = KHUtil.isNullMSG("customerId", customerId)  + KHUtil.isNullMSG("registerChannelId", registerChannelId) + KHUtil.isNullMSG("registerChannelName",registerChannelName);
                //log.debug("deal_result" + deal_result);
                int deal_flag = KHUtil.isNull(deal_result) ? 0 : -1;
                //log.debug("deal_flag" + deal_flag);

                //非空校验
                if(latestLogonTime==""){
                    latestLogonTime=null;
                }else{
                    latestLogonTime="'"+latestLogonTime+"'";
                }
                if(firstAssetTime==""){
                    firstAssetTime=null;
                }else{
                    firstAssetTime="'"+firstAssetTime+"'";
                }
                if(openingTime==""){
                    openingTime=null;
                }else{
                    openingTime="'"+openingTime+"'";
                }
                if(transferTime==""){
                    transferTime=null;
                }else{
                    transferTime="'"+transferTime+"'";
                }
                if(registerTime==""){
                    registerTime=null;
                }else{
                    registerTime="'"+registerTime+"'";
                }

                insertSQL[i*2] = "Insert Into account_deposit_details (customerId, latestLogonTime, firstAssetTime, firstAssetChannelId, firstAssetChannel, firstAssetAttribution, openingChannelId, openingChannelName, openingAttribution, openingTime, transferChannelId, transferChannelName, transferAttribution, transferTime, registerAttribution, registerTime, registerChannelId, registerChannelName, registerChannelId1, registerChannelName1, registerChannelId2, registerChannelName2, registerChannelId3, registerChannelName3, registerChannelId4, registerChannelName4,createtime,deal_flag,deal_result)  Values ('" + customerId+ "', " +latestLogonTime+ ", " +firstAssetTime+ ", '" +firstAssetChannelId+ "', '" +firstAssetChannel+ "', '" +firstAssetAttribution+ "', '" +openingChannelId+ "', '" +openingChannelName+ "', '" +openingAttribution+ "', " +openingTime+ ", '" +transferChannelId+ "', '" +transferChannelName+ "', '" +transferAttribution+ "', " +transferTime+ ", '" +registerAttribution+ "', " +registerTime+ ", '" +registerChannelId+ "', '" +registerChannelName+ "', '" +registerChannelId1+ "', '" +registerChannelName1+ "', '" +registerChannelId2+ "', '" +registerChannelName2+ "', '" +registerChannelId3+ "', '" +registerChannelName3+ "', '" +registerChannelId4+ "', '" +registerChannelName4+"',now(),'"+deal_flag+"','"+deal_result+"')";
                //落库更新customer
                insertSQL[i*2+1] = "update  Customer c  set c.registerChannelId=case when c.registerChannelId is null or c.registerChannelId='' then '" + registerChannelId+ "' else c.registerChannelId end,c.registerChannelName=case when c.registerChannelName is null or c.registerChannelName='' then '" + registerChannelName+ "' else c.registerChannelName end,c.registerAttribution=case when c.registerAttribution is null or c.registerAttribution='' then '" + registerAttribution+ "' else c.registerAttribution end,c.transferTime=case when c.transferTime is null then " + transferTime+ " else c.transferTime end,c.transferChannelId=case when c.transferChannelId is null or c.transferChannelId='' then '" + transferChannelId+ "' else c.transferChannelId end,c.transferChannelName=case when c.transferChannelName is null or c.transferChannelName='' then '" + transferChannelName+ "' else c.transferChannelName end,c.transferAttribution=case when c.transferAttribution is null or c.transferAttribution='' then '" + transferAttribution+ "' else c.transferAttribution end,c.openingChannelId=case when c.openingChannelId is null or c.openingChannelId='' then '" + openingChannelId+ "' else c.openingChannelId end,c.openingChannelName=case when c.openingChannelName is null or c.openingChannelName='' then '" + openingChannelName+ "' else c.openingChannelName end,c.openingAttribution=case when c.openingAttribution is null or c.openingAttribution='' then '" + openingAttribution+ "' else c.openingAttribution end,c.firstAssetTime=case when c.firstAssetTime is null then " + firstAssetTime+ " else c.firstAssetTime end,c.firstAssetChannelId=case when c.firstAssetChannelId is null or c.firstAssetChannelId='' then '" + firstAssetChannelId+ "' else c.firstAssetChannelId end,c.firstAssetChannel=case when c.firstAssetChannel is null or c.firstAssetChannel='' then '" + firstAssetChannel+ "' else c.firstAssetChannel end,c.firstAssetAttribution=case when c.firstAssetAttribution is null or c.firstAssetAttribution='' then '" + firstAssetAttribution+ "' else c.firstAssetAttribution end  where c.CUSTOMER_ID='"+customerId+"'";

            }

            // 处理批次信息
            String enddate = dateformat.format(System.currentTimeMillis());
            log.debug("提交数据库操作SQL集:" + insertSQL.toString());

            // 将数据插入数据库
            int[] sqlResult = eliteBean.updateBatch(insertSQL, dataSourceID);
            log.debug("提交数据库操作SQL结果:" + sqlResult.toString());

            // 生成处理完成时间
            endTime = System.currentTimeMillis();

            // 包装拼接返回JSONObject
            resultJson.put("resultcode", 1);
            resultJson.put("resultmessage", "处理完成,调用问题处理时长(毫秒):" + (endTime - startTime));
        } catch (Exception e) {
            endTime = System.currentTimeMillis();
            resultJson.put("resultcode", 4);
            resultJson.put("resultmessage", "处理失败:(" + e.getMessage() + ")" + "处理完成,调用问题处理时长(毫秒):" +(endTime -startTime));

        }

        return resultJson.toString();
    }


    // 处理入金状态提醒任务
    public static String remindCustData(EliteBean eliteBean, JSONObject inObject, String dataSourceID) {

        long startTime = System.currentTimeMillis();
        long endTime = System.currentTimeMillis();

        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createdate = dateformat.format(System.currentTimeMillis());

        // 生成批次号
        String batch_guid = KHUtil.getRandomString(36).toUpperCase();

        // 定义返回对象
        JSONObject resultJson = new JSONObject();

        try {

            JSONArray arrJsonArray = inObject.getJSONArray("data");
            int arrInt = arrJsonArray.size();
            log.debug("接入List数量:" + arrInt);

            String[] insertSQL = new String[arrInt];

            for (int i = 0; i < arrInt; i++) {

                JSONObject arrSmsJson = arrJsonArray.getJSONObject(i);

                String customerId = KHUtil.FastJsonNull(arrSmsJson.getString("customerId"));//华盛号
                String customerEnName = KHUtil.FastJsonNull(arrSmsJson.getString("customerEnName"));//客户英文姓名
                String arrivalRecordId = KHUtil.FastJsonNull(arrSmsJson.getString("arrivalRecordId"));//到账ID
                String depositAmount=KHUtil.FastJsonNull(arrSmsJson.getString("depositAmount"));//到账金额
                String currencyCode=KHUtil.FastJsonNull(arrSmsJson.getString("currencyCode"));//到账币种
                String remittanceBankName = KHUtil.FastJsonNull(arrSmsJson.getString("remittanceBankName"));//汇款银行
                String remittanceCardNo = KHUtil.FastJsonNull(arrSmsJson.getString("remittanceCardNo"));//汇款银行卡号
                String subBankCardNo = KHUtil.FastJsonNull(arrSmsJson.getString("subBankCardNo"));//子账户号码
                String noticeTime=KHUtil.FastJsonNull(arrSmsJson.getString("noticeTime"));//通知时间
                String amountArrivalTime=KHUtil.FastJsonNull(arrSmsJson.getString("amountArrivalTime"));//金额到账时间


                String deal_result = KHUtil.isNullMSG("customerId", customerId)  +KHUtil.isNullMSG("arrivalRecordId", arrivalRecordId)+KHUtil.isNullMSG("depositAmount", depositAmount)+KHUtil.isNullMSG("currencyCode", currencyCode)+KHUtil.isNullMSG("noticeTime", noticeTime)+KHUtil.isNullMSG("amountArrivalTime", amountArrivalTime);
                int deal_flag = KHUtil.isNull(deal_result) ? 0 : -1;

                //非空校验
                if(noticeTime==""){
                    noticeTime=null;
                }else{
                    noticeTime="'"+noticeTime+"'";
                }
                if(amountArrivalTime==""){
                    amountArrivalTime=null;
                }else{
                    amountArrivalTime="'"+amountArrivalTime+"'";
                }

                insertSQL[i] = "Insert Into hst_Deposit_Status_Remind (customerid,DepositStatus,customerEnName,arrivalRecordId,depositAmount,currencyCode,remittanceBankName,remittanceCardNo,subBankCardNo,noticeTime,amountArrivalTime,Createtime,deal_flag,deal_result) Values ('" + customerId+ "',1,'" + customerEnName+ "', '" + arrivalRecordId+ "', '" + depositAmount+ "', '" + currencyCode+ "', '" + remittanceBankName+ "', '" + remittanceCardNo+ "', '" + subBankCardNo+ "', " + noticeTime+ ", " + amountArrivalTime+ ", Now(),'"+deal_flag+"','"+deal_result+"')";

            }

            // 处理批次信息
            String enddate = dateformat.format(System.currentTimeMillis());

            log.debug("提交数据库操作SQL集:" + insertSQL.toString());

            // 将数据插入数据库
            int[] sqlResult = eliteBean.updateBatch(insertSQL, dataSourceID);
            log.debug("提交数据库操作SQL结果:" + sqlResult.toString());

            // 生成处理完成时间
            endTime = System.currentTimeMillis();

            // 包装拼接返回JSONObject
            resultJson.put("resultcode", 1);
            resultJson.put("resultmessage", "处理完成,调用问题处理时长(毫秒):" + (endTime - startTime));
        } catch (Exception e) {
            endTime = System.currentTimeMillis();
            resultJson.put("resultcode", 4);
            resultJson.put("resultmessage", "处理失败:(" + e.getMessage() + ")" + "处理完成,调用问题处理时长(毫秒):" +(endTime -startTime));

        }

        return resultJson.toString();
    }

}
